home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / snip9_91.arc / LBITOPS.C < prev    next >
C/C++ Source or Header  |  1991-09-17  |  665b  |  27 lines

  1. /*
  2. **  large bit array operations by Scott Dudley
  3. */
  4.  
  5. #include <limits.h>
  6.  
  7. #define BitOff(a,x) ((void)((a)[(x)/CHAR_BIT] &= ~(1 << ((x) % CHAR_BIT))))
  8. #define BitOn(a,x)  ((void)((a)[(x)/CHAR_BIT] |= (1 << ((x) % CHAR_BIT))))
  9. #define IsBit(a,x)  ((a)[(x)/CHAR_BIT] & (1 << ((x) % CHAR_BIT)))
  10.  
  11. #include <stdio.h>
  12.  
  13. main()
  14. {
  15.         char array[64];
  16.  
  17.         memset(array,'\0',sizeof(array));
  18.  
  19.         BitOn(array,5);
  20.         BitOn(array,12);
  21.         BitOn(array,500);
  22.  
  23.         if (IsBit(array,5) && IsBit(array,12) && IsBit(array,500))
  24.                 puts("These functions seemed to work!");
  25.         else puts("Something's broken here!");
  26. }
  27.